package com.liugh.service.zhongche.Imp;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.liugh.entity.standard.StandardItem;
import com.liugh.entity.standard.StandardSystem;
import com.liugh.mapper.zhongche.StandardItemMapper;
import com.liugh.mapper.zhongche.StandardSystemMapper;
import com.liugh.service.zhongche.IStandardSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**标准体系 .
 * Created by Fatao on 2018/10/29 .
 */
@Service
public class StandardSystemServiceImpl implements IStandardSystemService {



    @Autowired
    private StandardSystemMapper standardSystemMapper;


    @Autowired
    private StandardItemMapper standardItemMapper;




    /**
     * 只给十条信息的模糊查标准编号 .
     * @param standNo .
     * @return .
     */
    public List<StandardItem> findItemByNo(String standNo) {
        if (standNo != null) {
            List<StandardItem> list = standardItemMapper.selectPage(new Page<StandardItem>(1,10), new EntityWrapper<StandardItem>().like("stand_no", standNo));
            if (!list.isEmpty()) {
                return list;
            }
        }
        return null;

    }






    /**
     * 标准体系添加节点.
     * @return .
     */
    @Override
    public StandardSystem addSystem(StandardSystem standardSystem) {
        return standardSystemMapper.insert(standardSystem) > 0 ? standardSystem : null;
    }





    /**
     * 删除标准体系节点 .
     * @param id .
     * @return .
     */
    public int delStandardSystem(int id) {
        return standardSystemMapper.deleteById(id);
    }

    /**
     * 修改标准节点 .
     * @param standardSystem .
     * @return .
     */
    public StandardSystem updateStandSystem(StandardSystem standardSystem) {
        return standardSystemMapper.updateById(standardSystem) > 0 ? standardSystem : null;
    }





    /**
     * 获取所有的节点,type = 0 .
     * @return .
     */
    public List<StandardSystem> getStandardSystemList() {
        return standardSystemMapper.selectList(new EntityWrapper<StandardSystem>().eq("type", 0));
    }

    /**
     * 根据父节点获取标准 ,type = 1.
     * @param parentId .
     * @return .
     */
    public List<StandardSystem> getStandardSystemItem(int parentId) {
        return standardSystemMapper.selectList(new EntityWrapper<StandardSystem>().eq("parent_id", parentId).and().eq("type", 1));
    }


    /**
     * 根据id查找节点 .
     * @param id .
     * @return .
     */
    public StandardSystem getStandardSystemById(int id) {
        return standardSystemMapper.selectById(id);
    }






}
